package com.xj.edu.hotel.controller;

import com.xj.edu.hotel.domain.City;
import com.xj.edu.hotel.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 查询所有城市数据以及每个城市的酒店数量
     */
    @RequestMapping("hotelCount")
    public String selectHotelCount(Model model){
       List<City> citys = cityService.selectHotelCount();
       model.addAttribute("city",citys);
       return "city";
    }

    /**
     * 查询每个城市的各类酒店的
     */
    @RequestMapping("hotelTypeCount")
    public String selectHotelTypeCount(String cityName,Model model){
        List<City> cityList = cityService.selectHotelTypeCount(cityName);
        model.addAttribute("city",cityList);
        return "cityHotel";
    }


    @RequestMapping("findAllCity")
    @ResponseBody
    public List<City> findCity(Model model){
       List<City> citys = cityService.findCity();
       //model.addAttribute("cityList",citys);
       return citys;
    }



}
